/**
 * date: 2010-08-30
 */
package com.epro.dx.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.TextView;

import com.baifendian.mobile.BfdAgent;
import com.epro.dx.R;
import com.epro.dx.activity.chagepassword.ChangePasswordActivity;
import com.epro.dx.activity.coupon.CouponActivity;
import com.epro.dx.activity.forgetpassword.ForgetPasswordSubmitActivity;
import com.epro.dx.activity.messagecenter.MessageCenterActivity;
import com.epro.dx.activity.myaddress.MyAddressBookActivity;
import com.epro.dx.activity.order.MyOrdersActivity;
import com.epro.dx.activity.order.OrderPlaceActivity;
import com.epro.dx.activity.order.ShippingTrackingActivity;
import com.epro.dx.listenner.MyAsyncTaskListenner;
import com.epro.dx.task.GetIsNotReadAsyncTask;
import com.epro.dx.task.GetOneKeyFilterSettingsAsyncTask;
import com.epro.dx.task.GetTopCategoryAsyncTask;
import com.epro.dx.task.SetShippingTask;
import com.epro.dx.util.ActivityUtil;
import com.epro.dx.util.AsyncTaskUtil;
import com.epro.dx.util.GlobalConfig;
import com.epro.dx.widget.BottomBtn;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.HitBuilders.EventBuilder;
import com.google.android.gms.analytics.Tracker;
import com.weipu.common.DXApplication;
import com.weipu.common.DXApplication.TrackerName;
import com.weipu.common.constants.Constant;
import com.weipu.common.constants.ServerConstant;
import com.weipu.common.facade.exception.DxException;
import com.weipu.common.facade.factory.ProviderFactory;
import com.weipu.common.facade.model.OrderProductModel;
import com.weipu.common.facade.model.UserModel;
import com.weipu.common.subject.RedDotSubjectImpl;
import com.weipu.common.util.AlertToast;
import com.weipu.common.util.Logger;
import com.weipu.common.util.StringUtil;
import com.weipu.common.util.ThreadUtil;
import com.weipu.common.util.utils.SPUtils;

import cn.jpush.android.api.JPushInterface;

import static com.weipu.common.constants.ServerConstant.Parameter.PARAMETER_ACTION_TYPE_JGRECEIVER;
import static com.weipu.common.constants.ServerConstant.Parameter.PARAMETER_ACTION_TYPE_MESSAGECENTER;

/**
 * 登录
 *
 * @author qsc255
 * @version [版本号, 2010-8-30]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class LoginActivity extends BaseFragmentActivity implements
        OnClickListener, OnFocusChangeListener {
    private static final String TAG = LoginActivity.class.getSimpleName();

    private UserModel userModel;

    private EditText editName;

    private EditText editPwd;

    private CheckBox cbRemenber;

    private Button loginBtn;

    /**
     * 来自哪个页面 类型
     */
    int actionType;

    private String account;

    private String password;

    /**
     * 是否记住密码,默认不记住
     */
    private boolean isRemember = false;

    /**
     * 记住账号密码标志值
     */
    private static final String IS_REMEMBER_FLAG = "1";

    /**
     * 不记住账号密码标志值
     */
    private static final String NOT_REMEMBER_FLAG = "0";

    private String rememberUserName = "";

    private String rememberUserPwd = "";

    private String isRememberStr = "";

    private TextView forgetPwd;

    private EditText passwordEt;

    private boolean isChangePwd;

    private Tracker tracker;

    private EventBuilder eventBuilder;

    private boolean isClearCart;

    private String homeCurrentTag;

    private String acountClickItem = null;

    private String currencyCodeStr;
    private boolean isKnowNewFun;
    private SPUtils spUtils;
    private String orderNumber;
    private boolean isNeedReSendJg;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        tracker = ((DXApplication) getApplication()).getTracker(TrackerName.APP_TRACKER);
        eventBuilder = new HitBuilders.EventBuilder();
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_login);
        // setLeftBtnContent(false, R.string.btn_title_cancel);
        setRightBtnContent(R.string.title_signup).setOnClickListener(this);
        setTitleContent(R.string.title_login);
        if (null != getIntent()) {
            isChangePwd = getIntent().getBooleanExtra("changePwd", false);
            isClearCart = getIntent().getBooleanExtra("isClearCart", false);
            currencyCodeStr = getIntent().getStringExtra(ServerConstant.Parameters.PARAMETERS_CURRENCYCODESTR);
            acountClickItem = getIntent().getStringExtra(ServerConstant.Parameter.PARAMETER_FROMACOUNTCLICK);
        }
        Bundle data = getIntent().getExtras();
        if (null != data) {
            actionType = data.getInt(
                    ServerConstant.Parameter.PARAMETER_NAME_LOGIN_ACTION_TYPE,
                    -1);
            homeCurrentTag = data.getString(HomeActivity.CURRENT_TAB_TAG);
            orderNumber = data.getString(ServerConstant.Parameter.PARAMETER_NAME_ORDER_NUMBER, "");
            isNeedReSendJg = data.getBoolean(ServerConstant.Parameter.PARAMETER_NAME_IS_NEED_RESEND_JG, false);
        }
        intView();
        setListenner();

        cbRemenber.setChecked(isRemember);
        setLeftBtnContent(true, -1);
        // 登录按钮事件监听
        loadConfig();

        spUtils = new SPUtils(getResources().getString(R.string.app_name_en));
        isKnowNewFun = spUtils.getBoolean(Constant.Global.IS_KONW_NEW_FUN, false);
    }

    @Override
    protected void onResume() {
        super.onResume();
        tracker.setScreenName("Login");
        tracker.send(new HitBuilders.ScreenViewBuilder().build());

        //百分点推荐
        BfdAgent.setDebugMode(Constant.BFD_DEBUGMODEL);
        BfdAgent.onResume(getApplicationContext());
    }

    @Override
    protected void onPause() {
        super.onPause();
        tracker.setScreenName(null);
        BfdAgent.onPause(getApplicationContext());
    }

    private void intView() {
        editName = (EditText) findViewById(R.id.txt_name);
        editPwd = (EditText) findViewById(R.id.txt_pwd);
        forgetPwd = (TextView) findViewById(R.id.forget_password);
        loginBtn = (Button) findViewById(R.id.btn_login);
        cbRemenber = (CheckBox) findViewById(R.id.chk_remember);
        editPwd.setOnFocusChangeListener(this);
    }

    private void setListenner() {
        forgetPwd.setOnClickListener(this);
        loginBtn.setOnClickListener(this);
        cbRemenber.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {
                if (isChecked) {
                    isRemember = true;
                } else {
                    isRemember = false;
                }
            }
        });

        editName.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                                      int arg3) {
                // TODO Auto-generated method stub

            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1,
                                          int arg2, int arg3) {
                // TODO Auto-generated method stub

            }

            @Override
            public void afterTextChanged(Editable arg0) {
                if (TextUtils.equals(IS_REMEMBER_FLAG, isRememberStr)) {
                    if (null != rememberUserName
                            && !"".equals(rememberUserName)) {
                        if (!rememberUserName.equals(arg0.toString())) {
                            cbRemenber.setChecked(false);
                            editPwd.setText("");
                        } else {
                            cbRemenber.setChecked(true);
                            editPwd.setText(rememberUserPwd);
                        }
                    }
                }
            }
        });
    }

    /**
     * 加载用户信息:用户是否勾选了Remeber me,及加载用户名、密码等
     *
     * @return void [返回类型说明]
     * @throws throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */
    private void loadConfig() {

        // 用户信息预设
        String[] key = {
                ServerConstant.Parameter.PARAMETER_NAME_USER_IS_REMEBER,
                ServerConstant.Parameter.PARAMETER_NAME_USER_EMAIL,
                ServerConstant.Parameter.PARAMETER_NAME_USER_PWD};
        // 读取配置
        Map<String, String> userConfig = StringUtil.getConfig(this, key);

        if (null == userConfig) {
            return;
        }

        // 记住密码
        if (TextUtils.equals(IS_REMEMBER_FLAG, userConfig.get(key[0]))) {
            rememberUserName = userConfig.get(key[1]);
            rememberUserPwd = userConfig.get(key[2]);
            isRememberStr = userConfig.get(key[0]);
            // 设置用户信息到对应的控件元素上
            editName.setText(TextUtils.isEmpty(userConfig.get(key[1])) ? ""
                    : userConfig.get(key[1]));
            editPwd.setText(userConfig.get(key[2]));
            cbRemenber.setChecked(true);
        } else {
            rememberUserName = userConfig.get(key[1]);
            cbRemenber.setChecked(false);
        }
    }

    /**
     * 点击登录按钮后， 参数校验、显示登录进度条
     *
     * @return void [返回类型说明]
     * @throws throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */
    private void login() {
        // 获取字段信息并验证
        account = editName.getText().toString().trim();
        // 账号为空，返回
        if (TextUtils.isEmpty(account)) {
            AlertToast.alert(LoginActivity.this,
                    R.string.user_login_validate_account_is_null, editName);
            return;
        }

        // 账号长度验证
        if (account.length() < Constant.Rule.EMAIL_MIN_LENGTH
                || account.length() > Constant.Rule.TEXT_MAX_LENGTH) {
            AlertToast.alert(
                    LoginActivity.this,
                    getString(R.string.user_login_validate_account_length,
                            Constant.Rule.EMAIL_MIN_LENGTH,
                            Constant.Rule.TEXT_MAX_LENGTH), editName);
            return;
        }

        // // 账号规则验证
        // if (!StringUtil.isEmail(account))
        // {
        // AlertToast.alert(LoginActivity.this,
        // R.string.user_login_validate_account_rule, editName);
        // return;
        // }

        // 获取密码、验证
        password = editPwd.getText().toString().trim();
        // 密码
        if (TextUtils.isEmpty(password)) {
            AlertToast.alert(LoginActivity.this,
                    R.string.user_login_validate_pwd_is_null, editPwd);
            return;
        }
        // 密码长度验证
        if (password.length() > Constant.Rule.PWD_MAX_LENGTH) {
            AlertToast.alert(
                    LoginActivity.this,
                    getString(R.string.user_login_validate_pwd_length,
                            Constant.Rule.PWD_MIN_LENGTH,
                            Constant.Rule.PWD_MAX_LENGTH), editPwd);
            return;
        }
        isRemember = cbRemenber.isChecked();
        // 验证完毕调接口登录

        // new LoadingUser().execute();
        AsyncTaskUtil.executeTask(new LoadingUser());

    }

    /**
     * 完成activity间跳转
     *
     * @return boolean [返回类型说明]
     * @throws throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */
    private void startByActionType() {
        Intent getIndtent = getIntent();
        Intent intent = new Intent();
        intent.putExtra(
                ServerConstant.Parameter.PARAMETER_NAME_LOGIN_ACTION_TYPE,
                ServerConstant.Parameter.PARAMETER_ACTION_TYPE_LOGIN);
        // 设置返回Activity
        switch (actionType) {
            // 从详情界面添加收藏过来的
            case ServerConstant.Parameter.PARAMETER_ACTION_TYPE_PRODUCT_DETAIL:
                // intent.setClass(this, DetailActivity.class);
                break;
            // 从主页过来的
            case ServerConstant.Parameter.PARAMETER_ACTION_TYPE_NEWMAIN:
                intent.setClass(this, HomeActivity.class);
                intent.putExtra(HomeActivity.CURRENT_TAB_TAG,
                        getString(HomeActivity.titleArray[0]));
                break;
            case ServerConstant.Parameter.PARAMETER_ACTION_TYPE_MYACCOUNT:
                if (!TextUtils.isEmpty(acountClickItem)) {
                    //根据登陆前点击的条目，登陆后直接跳转到原目标页面
                    if ("myCoupon".equals(acountClickItem)) {
                        intent.setClass(LoginActivity.this, CouponActivity.class);
                        intent.putExtra("pageNumber", 1);
                    }
                    if ("myWishList".equals(acountClickItem)) {
                        intent.setClass(LoginActivity.this, FavoritesActivity.class);
                    }
                    if ("myAddressBook".equals(acountClickItem)) {
                        intent.setClass(LoginActivity.this, MyAddressBookActivity.class);
                        intent.putExtra("fromChooseAdd", false);
                    }
                    if ("browsed".equals(acountClickItem)) {
                        intent.setClass(LoginActivity.this, BrowseAcitivty.class);
                    }
                    if ("changePassword".equals(acountClickItem)) {
                        intent.setClass(LoginActivity.this, ChangePasswordActivity.class);
                    }
                    if ("orderAll".equals(acountClickItem)) {
                        intent.setClass(LoginActivity.this, MyOrdersActivity.class);
                        intent.putExtra("fragmentIndex", 0);
                    }
                    if ("orderPendingPayment".equals(acountClickItem)) {
                        intent.setClass(LoginActivity.this, MyOrdersActivity.class);
                        intent.putExtra("fragmentIndex", 1);
                    }
                    if ("orderPendingDelivery".equals(acountClickItem)) {
                        intent.setClass(LoginActivity.this, MyOrdersActivity.class);
                        intent.putExtra("fragmentIndex", 2);
                    }
                    if ("orderFullShipment".equals(acountClickItem)) {
                        intent.setClass(LoginActivity.this, MyOrdersActivity.class);
                        intent.putExtra("fragmentIndex", 3);
                    }
                    if ("orderTrack".equals(acountClickItem)) {
                        intent.setClass(LoginActivity.this, TrackSubscriptActivity.class);
                        //在这里通知新功能已读，保存已读的状态,不过只有在新功能还未读的情况下才通知观察者
                        if (!isKnowNewFun) {
                            RedDotSubjectImpl.getInstance().notifyObserver();
                        }
                    }
                    break;
                } else {
                    finish();
                    return;
                }
                // 收藏夹
            case ServerConstant.Parameter.PARAMETER_ACTION_TYPE_WISH:
                intent.setClass(this, FavoritesActivity.class);
                break;
            // check out
            case ServerConstant.Parameter.PARAMETER_ACTION_TYPE_MYCART:
            case ServerConstant.Parameter.PARAMETER_ACTION_TYPE_PRODUCT_DETIAL:
                intent.setClass(this, OrderPlaceActivity.class);
                intent.putExtra(HomeActivity.CURRENT_TAB_TAG,
                        getString(HomeActivity.titleArray[2]));
                //---------修改：加入所需数据，实现购物车登陆后直接跳转到Checkout页面----------
                ArrayList<OrderProductModel> orderProductModels = getIndtent
                        .getParcelableArrayListExtra(ServerConstant.Parameter.PARAMETER_NAME_ORDER_ORDERMAP);
                intent.putParcelableArrayListExtra(
                        ServerConstant.Parameter.PARAMETER_NAME_ORDER_ORDERMAP,
                        orderProductModels);
                //加入是否需要清除服务端购物车数据的标记
                intent.putExtra("isClearCart", isClearCart);
//				// 传递一个标识，表示从mycartActivity付款的，此时付款完成后需要删除购物车的商品
//			intent.putExtra(
//					ServerConstant.Parameter.PARAMETER_NAME_FROM_ACTIVITY,
//					ServerConstant.ActionConstant.FORM_MYCART_ACTIVITY);
                if (!TextUtils.isEmpty(currencyCodeStr)) {
                    intent.putExtra(ServerConstant.Parameters.PARAMETERS_CURRENCYCODESTR, currencyCodeStr);
                }
                if (getIntent() != null) {
                    intent.putExtra(ServerConstant.Parameters.PARAMETERS_DISCOUNT, getIntent().getDoubleExtra(ServerConstant.Parameters.PARAMETERS_DISCOUNT, 0));
                    intent.putExtra(ServerConstant.Parameters.PARAMETERS_GRANDTOTAL, getIntent().getDoubleExtra(ServerConstant.Parameters.PARAMETERS_GRANDTOTAL, 0));
                    intent.putExtra(ServerConstant.Parameters.PARAMETERS_SUBTOTAL, getIntent().getDoubleExtra(ServerConstant.Parameters.PARAMETERS_SUBTOTAL, 0));
                    intent.putExtra(ServerConstant.Parameters.PARAMETERS_RETURNSC, getIntent().getFloatExtra(ServerConstant.Parameters.PARAMETERS_RETURNSC, 0));
                }
                break;
            // // my orders
            // case ServerConstant.Parameter.PARAMETER_ACTION_TYPE_ORDER_DETAIL:
            // intent.setClass(this, MyOrdersActivity.class);
            // break;
            // MyCoupon
            case ServerConstant.Parameter.PARAMETER_ACTION_TYPE_MYCOUPON:
            case ServerConstant.Parameter.PARAMETER_ACTION_TYPE_AUTO_LOGIN_FAIL:
//			finish();
                intent.setClass(this, HomeActivity.class);
                break;
//			return;
//			intent.setClass(this, CouponActivity.class);
//			intent.putExtra("pageNumber", 1); 
            case ServerConstant.Parameter.PARAMETER_ACTION_TYPE_COUPONMARKET:
                if (null != getIndtent) {
                    intent.putExtra("CouponCode", getIndtent.getStringExtra("CouponCode"));
                    intent.putExtra("CouponIndex", getIndtent.getIntExtra("CouponIndex", -1));
                }
                LoginActivity.this.setResult(10, intent);
                finish();
                return;
            case PARAMETER_ACTION_TYPE_MESSAGECENTER:
                //跳转到消息中心
                intent.setClass(LoginActivity.this, MessageCenterActivity.class);
                startActivity(intent);
                finish();
                return;

            //接收推送，从激光推送过来的
            case PARAMETER_ACTION_TYPE_JGRECEIVER:
                if (isNeedReSendJg) {
                    Intent toReceiverIntent = new Intent(JPushInterface.ACTION_NOTIFICATION_OPENED);
//				toReceiverIntent.putExtra("Intent", getIntent().getParcelableArrayExtra("Intent"));
                    sendBroadcast(toReceiverIntent);
                } else {
                    intent.setClass(LoginActivity.this, ShippingTrackingActivity.class);
                    intent.putExtra("OrderNumber", orderNumber)
                            .putExtra("CurrencyCode", "")
                            .putExtra("fromOrderTrackPage", false);
                    startActivity(intent);
                }

                finish();
                return;

            default:
                intent.setClass(this, HomeActivity.class);
                break;
        }
        if (ServerConstant.Parameter.PARAMETER_ACTION_TYPE_PRODUCT_DETAIL != actionType) {
            startActivity(intent);
        }
        finish();
    }

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (!v.isFocused()) {
            // 失去焦点，关闭键盘
            IBinder localIBinder = v.getWindowToken();
            ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(localIBinder, 2);
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            // 登录
            case R.id.btn_login: {
                eventBuilder.setCategory("Click").setAction("Login");
                tracker.send(eventBuilder.build());
                login();
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(loginBtn.getWindowToken(), 0);
                break;
            }
            // 注册
            case R.id.topbar_right_tv: {
                eventBuilder.setCategory("Click").setAction("Go to regist");
                tracker.send(eventBuilder.build());
                startActivity(new Intent(this, RegisterActivity.class));
                break;
            }
            case R.id.forget_password:
                eventBuilder.setCategory("Click").setAction("Forget password");
                tracker.send(eventBuilder.build());
                startActivity(new Intent(this, ForgetPasswordSubmitActivity.class));
                break;
            default:
                break;
        }
    }

    /**
     * 实现登录
     *
     * @author hjd008
     * @version [版本号, 2015-1-14]
     * @see [相关类/方法]
     * @since [产品/模块版本]
     */
    class LoadingUser extends AsyncTask<Void, Void, String> {
        //		ArrayList<OrderProductModel> localCartDatas;
        @Override
        protected void onPreExecute() {
            loginBtn.setEnabled(false);
//			showWaitingDialog();
            showLoadingLayout(null);
        }

        @Override
        protected String doInBackground(Void... params) {
            try {
                userModel = ProviderFactory.createUserServiceProvider().login(
                        account, password);
            } catch (DxException e) {
                return e.getErrCode();
            } catch (Exception e) {
                Logger.e("LoginActivity", "LoadingUser", e);
            }
//			localCartDatas= ProviderFactory
//					.createMyCartServiceDBProvider()
//					.selectMenusList(LoginActivity.this, "_id desc");
            return "0";
        }

        @Override
        protected void onPostExecute(String result) {
            //用户登录成功，使用默认配置注册物流信息推送功能
            registShippingPush();
            if (!isFinishing()) {
//				hideWaitingDialog();
                hideAllLayout();
                loginBtn.setEnabled(true);
            }

            if ("0".equals(result)) {
                /*
				 * //Testin 崩溃大师 用户登录名上传
				 * TestinAgent.setUserInfo(userModel.getEmail());
				 */
                GlobalConfig.getInstance().setShoppingCartChange(true);
//				Logger.i(TAG, "获得用户信息：" + userModel.getUsername());
                HashMap<String, String> userConfig = new HashMap<String, String>();

                userConfig.put(
                        ServerConstant.Parameter.PARAMETER_NAME_USER_ACCOUNT,
                        userModel.getUsername());
                userConfig.put(
                        ServerConstant.Parameter.PARAMETER_NAME_USER_EMAIL,
                        userModel.getEmail());
                userConfig.put(
                        ServerConstant.Parameter.PARAMETER_NAME_IS_LOGIN,
                        "true");
                userConfig.put(
                        ServerConstant.Parameter.PARAMETER_USER_CUSTOMERID,
                        userModel.getCustomerid());
                userConfig.put(
                        ServerConstant.Parameter.PARAMETER_NAME_USER_PWD,
                        password);
                userConfig.put(
                        ServerConstant.Parameter.PARAMETER_NAME_TOKEN,
                        userModel.getToken());
                // 勾选了Remeber me
                if (isRemember) {
                    userConfig
                            .put(ServerConstant.Parameter.PARAMETER_NAME_USER_IS_REMEBER,
                                    IS_REMEMBER_FLAG);
                } else {
                    userConfig
                            .put(ServerConstant.Parameter.PARAMETER_NAME_USER_IS_REMEBER,
                                    NOT_REMEMBER_FLAG);
                }
                StringUtil.saveConfig(LoginActivity.this, userConfig);
//				if (localCartDatas != null && localCartDatas.size() > 0) {
//					StringUtil.saveConfig("IsUploadSucc", "false");
//				}else{
//					StringUtil.saveConfig("IsUploadSucc", "true");
//				}
                //百分点推荐添加用户ID
                BfdAgent.onAddUser(getApplicationContext(), userModel.getCustomerid());

                //设置与极光推送的绑定关系 TODO 设置分组
                setJPushAlias("" + ActivityUtil.getCustomerID(), null);

                //获取用户的一键过滤设置
                AsyncTaskUtil.executeTask(new GetOneKeyFilterSettingsAsyncTask(LoginActivity.this, new MyAsyncTaskListenner() {

                    @Override
                    public void onPreTask() {
                    }

                    @Override
                    public void onPostTask(String result, Object obj) {
                        if ("0".equals(result)) {
                            //获取更新一级目录
                            AsyncTaskUtil.executeTask(new GetTopCategoryAsyncTask(LoginActivity.this, null));
                        }
                    }
                }));

                //获取用户是否有未读消息
                AsyncTaskUtil.executeTask(new GetIsNotReadAsyncTask(null));
                //更改标记刷新首页的推荐产品数据
                StringUtil.saveConfig("Home_RefreshBFD", "true");
                startByActionType();

            } else {
                AlertToast.alert(LoginActivity.this,
                        ServerConstant.ReturnCode.MESSAGEMAP.get(result));
            }
        }
    }

    /**
     * 使用默认配置注册物流信息推送功能
     */
    private void registShippingPush() {
        SetShippingTask setShippingTask = new SetShippingTask();
        setShippingTask.execute();
    }

    @Override
    protected View setLeftBtnContent(Boolean isBackIcon, int resId) {
        if (isChangePwd
                || actionType == ServerConstant.Parameter.PARAMETER_ACTION_TYPE_MYACCOUNT) {
            if (!isBackIcon && -1 != resId) {
                return null;
            } else {
                topbarLeftTv.setVisibility(View.VISIBLE);
                topbarLeftTv.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent();
                        intent.setClass(LoginActivity.this, HomeActivity.class);
                        if (!TextUtils.isEmpty(homeCurrentTag)) {
                            if (homeCurrentTag.equals(BottomBtn.ACCOUNT_TAG)) {
                                finish();
                                return;
                            }
                            intent.putExtra(HomeActivity.CURRENT_TAB_TAG,
                                    homeCurrentTag);
                        } else {
                            intent.putExtra(HomeActivity.CURRENT_TAB_TAG,
                                    getString(HomeActivity.titleArray[0]));
                        }
                        startActivity(intent);
                    }
                });
                if (isBackIcon) {
                    topbarLeftTv.setCompoundDrawablesWithIntrinsicBounds(
                            R.drawable.selector_topbar_back, 0, 0, 0);
                }
                if (-1 != resId) {
                    topbarLeftTv.setText(resId);
                }
            }
            return topbarLeftTv;
        } else {
            return super.setLeftBtnContent(isBackIcon, resId);
        }

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
//		if (keyCode == KeyEvent.KEYCODE_BACK) {
//			if (isChangePwd
//					|| actionType == ServerConstant.Parameter.PARAMETER_ACTION_TYPE_MYACCOUNT) {
////				Intent intent = new Intent();
////				intent.setClass(LoginActivity.this, HomeActivity.class);
////				intent.putExtra(HomeActivity.CURRENT_TAB_TAG,
////						getString(HomeActivity.titleArray[0]));
////				startActivity(intent);
//			}
//		}
        return super.onKeyDown(keyCode, event);
    }

}
